class Edit {
    constructor() {
        header("分类编辑")
        // additional 可选菜单
        // principal 已选菜单
        this.renderList()
    }

    renderList() {
        $(".principal").html()
        $(".additional").html()

        $(".principal").html(getItem("principal").map(v => `<li>${v.title}</li>`))
        $(".additional").html(getItem("additional").map(v => `<li>${v.title}</li>`))
        _(".principal li").tap(({v,i}) => i != 0 ? this.clickEvent("principal", "additional", {v,i}) : null )
        _(".additional li").tap(({v,i}) => this.clickEvent("additional", "principal", {v,i}))
        
    }

    clickEvent(principal, additional, item) {
        let {v,i} = item;
        // 先把数据添加到 可选菜单 中
        let getAdditional = getItem(additional)
        getAdditional.push(getItem(principal)[i])
        setItem(additional,getAdditional)
      
        setItem(principal,getItem(principal).filter(item => v.innerText != item.title))
        this.renderList()
    }
}

new Edit()